package com.harvest.scientific.ladder.page.adapter

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.harvest.scientific.ladder.R
import com.harvest.scientific.ladder.adpater.BaseMultiItemAdapter
import com.harvest.scientific.ladder.adpater.BaseQuickAdapter
import com.harvest.scientific.ladder.databinding.TermItemBinding
import com.harvest.scientific.ladder.ext.dp2px
import com.harvest.scientific.ladder.ext.getString
import com.harvest.scientific.ladder.ext.setMargin
import com.harvest.scientific.ladder.ext.setMaterialDrawable
import com.harvest.scientific.ladder.ext.visible
import com.harvest.scientific.ladder.res.JustUndividedPartBath

/**
 * @author：zenglingwen
 * @date：2024-06-15 18:11
 * @desc：
 */
class TermAdapter: BaseMultiItemAdapter<JustUndividedPartBath>(arrayListOf()) {

    class NormalItemHolder(val binding: TermItemBinding): RecyclerView.ViewHolder(binding.root)

    init {

        addItemType(0, object : OnMultiItemAdapterListener<JustUndividedPartBath, NormalItemHolder> {
            override fun onCreate(
                context: Context,
                parent: ViewGroup,
                viewType: Int
            ): NormalItemHolder {
                return NormalItemHolder(
                    TermItemBinding.inflate(
                        LayoutInflater.from(context),
                        parent,
                        false
                    )
                )
            }

            override fun onBind(
                holder: NormalItemHolder,
                position: Int,
                item: JustUndividedPartBath?
            ) {
                item?.let {
                    holder.binding.apply {
                        if (item.type == 0) {
                            root.setMaterialDrawable(
                                dp2px(6f), Color.parseColor("#EAEBF5"),
                                strokeWidth = dp2px(1f),
                                strokeColor = if (item.selected) context.getColor(R.color.color_28359B) else context.getColor(R.color.color_6628359b)

                            )
                        } else {
                            root.background = null
                        }
                        termTv.text = context.getString(
                            R.string.term_info,
                            item.antarcticPig.toString(),
                            (item.puzzledLoudSpecialist * item.antarcticPig).toString()
                        )
                        termTv.setTextColor(ContextCompat.getColor(context, if (item.type == 0) R.color.color_28359B else R.color.color_999))
                        termSelectIv.visible(item.selected && item.type == 0)
                        termLockIv.visible(item.type == 1)
                        root.setMargin(leftMargin = if (holder.bindingAdapterPosition == 0) 0 else dp2px(9f).toInt() )
                    }
                }
            }

        }).onItemViewType {position , list -> 0 }
    }

}